package org.miniframework.util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class FileUtil {

    /**
     * 按行读取文本内容
     * @param path
     * @return
     */
    public static String read(String path){
        BufferedReader reader;
        StringBuilder sb = new StringBuilder();
        String line;
        try {
            reader = new BufferedReader(new FileReader(path));
            while ((line = reader.readLine()) != null){
                sb.append(line).append(System.lineSeparator());
            }
        } catch (IOException e) {
            return null;
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String path = "C:\\Users\\86157\\Desktop\\cccc\\java-miniframework\\miniframework\\src\\main\\resources\\banner.txt";
        String content = FileUtil.read(path);
        if (content != null && content.contains("xiaochi")){
            content = content.replace("xiaochi","\033[35;4mxiaochi\033[0m");
        }
        System.out.println(content);
    }
}
